Charles Lanfear
May 23rd, 2018
ggmap for mashing up maps with ggplot2ggrepel to avoid overlapsggplot2 using coordinatestidycensus for obtaining Census Bureau datasf: Simple Features geometry for RIf you are interested in mapping, GIS, and geospatial analysis in R, acquire this book.
You may also consider taking Jon Wakefield's CSSS 554: Statistical Methods for Spatial Data, however it is challenging and focuses more heavily on statistics than mapping.
Also, in most terms, CSDE offers workshops in GIS using QGIS and/or ArcGIS.
I recommend QGIS because it is free, open-source software with an extensive feature set and large user community.
ggmap is a package that works with ggplot2 to plot spatial data directly on map images downloaded from Google Maps, OpenStreetMap, and Stamen Maps (good artistic/minimal options).
What this package does for you:
get_map()) at the location and scale you wantggplot objectggplot layers like points, 2D density plots, text annotationsIn Week 5, we looked at types of incidents the Seattle Police Department responded to in a single day. Now, we'll look at where those were.
library(tidyverse); library(ggmap)
spd_raw <- read_csv("https://clanfear.github.io/CSSS508/Seattle_Police_Department_911_Incident_Response.csv")
qmplot will automatically set the map region based on your data:
qmplot(data = spd_raw,
x = Longitude,
y = Latitude,
color = "firebrick",
alpha = 0.5)
All I provided was numeric latitude and longitude, and it placed the data points correctly on a raster map of Seattle.
We can give qmap() a text query—like a Google Maps search—and it will do its best to produce a map centered on that location.
qmap(location = "mary gates hall university of washington",
zoom = 15,
maptype = "watercolor",
source = "stamen")
Both qmplot() and qmap() are wrappers for a function called get_map() that retrieves a base map layer. Some options:
location= search query or numeric vector of longitude and latitudezoom= a zoom level (3 = continent, 10 = city, 21 = building)source=
"google": Google Maps for general purpose maps"osm": OpenStreetMaps, general purpose but open access"stamen": Aesthetically pleasing alternatives based on OpenStreetMapsmaptype=
"terrain", "terrain-background", "satellite", "roadmap", "hybrid""watercolor", "toner", "toner-background", "toner-lite"color= "color" or "bw"source="stamen" yields interesting looking maps—including nice black and white styles—which
may look better than Google or OpenStreetMaps in publications and presentations.
qmap(location = "pike place market",
zoom = 14,
maptype = "toner-background",
source = "stamen")
source="google" produces the same rasters you would get using the Google Maps website.
qmap(location = "seattle",
zoom = 8,
maptype = "terrain",
source = "google")